package org.alerve.android.resourcebuilder.modules;

import org.alerve.android.resourcebuilder.IModule;
import org.alerve.android.resourcebuilder.Layout;

/**
 * 
 * This {@link IModule} uses an {@link IObjectInflator} to inflate the
 * interface of the given object.
 * 
 * @author pabs87@gmail.com
 * 
 * @param <Type>
 */
public abstract class InflatorModule<Type> implements IModule<Type> {

	public boolean build(Type subject) {
		Class<?> CLASS = subject.getClass();
		Layout layout = subject.getClass().getAnnotation(Layout.class);
		// Navigate the class hierarchy to find an Layout
		while (layout == null && CLASS != Object.class) {
			CLASS = CLASS.getSuperclass();
			layout = CLASS.getAnnotation(Layout.class);
		}
		return inflate(subject, layout);
	}

	protected  abstract boolean inflate(Type subject, Layout layout);

}
